package host.skiree.nettydemo.server.service.impl;

import host.skiree.nettydemo.message.*;
import host.skiree.nettydemo.server.dto.impl.UserChannelImpl;
import host.skiree.nettydemo.server.service.MessageHandler;
import io.netty.channel.ChannelHandlerContext;

import java.util.HashSet;
import java.util.Set;

/**
 * @author gcl
 * @date 2022/9/20 13:46
 */
public class UserList implements MessageHandler {

    @Override
    public void handleMessage(ChannelHandlerContext ctx, Message message) {
        Set<String> names = new HashSet<>();
        // 不能使用 .inverse().keySet() 来获取数据
        UserChannelImpl.USER_CHANNEL_MAP.forEach((k ,v) -> {
            names.add(v);
        });
        ctx.writeAndFlush(new UserListResponseMessage(names));
    }

}
